<template>
  <div>
    <h1>商家列表</h1>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="userId" label="Id" />
      <el-table-column prop="userName" label="账号" />
      <el-table-column prop="userPass" label="密码" />
      <el-table-column prop="userMobile" label="电话号" />
    </el-table>
    <div class="demo-pagination-block">
      <el-pagination
        v-model:current-page="searchData.pageNum"
        v-model:page-size="searchData.pageSize"
        :page-sizes="[2, 3, 4, 5]"
        :size="size"
        :disabled="disabled"
        :background="background"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";
import { loginService } from "../api/api";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
import { getUserListService } from "../api/api";
const router = useRouter();
const tableData = ref([]);
const searchData = ref({
  pageNum: 1,
  pageSize: 2,
});
const total = ref(0);
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchData.value.pageSize = val;
  userList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchData.value.pageNum = val;
  userList();
};
const userList = () => {
  getUserListService(searchData.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};
onMounted(() => {
  userList();
});
</script>
